<?php

/* @var $this yii\web\View */

$this->title = 'Spike抢购动作串联';
?>
<div class="site-index">

    <div class="jumbotron">

    </div>

    <div class="body-content">
        <!-- 抢购商品列表 -->
        <dib class="row">
            <div class="col-sm-3">
                抢购商品列表:
            </div>

            <div class="col-sm-9">
                <a class="btn btn-primary" target="_blank" href="http://api.spike.com/?r=active-good/active-good-list">
                    抢购商品列表
                </a>
            </div>
        </dib>

        <div class="row">
            <div class="col-sm-3">
                检查 活动商品 是否有效
            </div>
            <div class="col-sm-9">
                <a class="btn  btn-primary" onclick="checkActGoods()">
                    检查 "2_3" 商品状态
                </a>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-3">
                人机检查 - 逻辑问题
            </div>
            <div class="col-sm-9">
                <form id="checkMachine_form">
                    <input name="user_sign" value="" type="hidden" />
                </form>

                <a class="btn  btn-primary" onclick="checkMachine()">
                    人机检查
                </a>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-3">
                下单抢购
            </div>
            <div class="col-sm-9">
                <form id="toBuy_form">
                    <input name="active_id" value="2" type="hidden" />
                    <input name="goods_id" value="3" type="hidden" />
                    <input name="goods_num" value="1" type="hidden" />
                    <input name="user_sign" value="" type="hidden" />
                    <input name="question_sign" value="" type="hidden" />
                    <input name="ask" value="" type="text" />
                    <input name="answer" value="" type="text" />
                </form>

                <a class="btn  btn-primary" onclick="toBuy()">
                    下单抢购
                </a>
            </div>
        </div>

    </div>
</div>
<script type="text/javascript" src="/js/jquery-3.2.1.js"></script>
<script type="text/javascript">

    /* 检查活动状态 */
    function checkActGoods()
    {
        $.ajax({
            type: "GET",
            url: "http://api.spike.com/?r=astatus/index&aid=2&gid=3",
            dataType: "json",
            success: function( data ){
                console.log( data );
                $("#checkMachine_form input[name='user_sign']").val( data.user_sign );
                $("#toBuy_form input[name='user_sign']").val( data.user_sign );
            }
        });
    }

    /* 检查是否为机器人 */
    function checkMachine()
    {
        $.ajax({
            type: "POST",
            url: "http://api.spike.com/?r=question/set-question",
            dataType: "json",
            data:$("#checkMachine_form").serialize(),
            success: function( json ){
                var data = json.data;
                $("#toBuy_form input[name='question_sign']").val( data.sign );
                $("#toBuy_form input[name='ask']").val( data.ask );
            }
        });
    }

    /* 检查是否为机器人 */
    function toBuy()
    {
        $.ajax({
            type: "POST",
            url: "http://api.spike.com/?r=buy/buy",
            dataType: "json",
            data:$("#toBuy_form").serialize(),
            success: function( json ){
                alert( json.msg );
            }
        });
    }
</script>